#!/usr/bin/env python3

class Student:
    def __init__(self):
        print("进入构造方法...")

    def __enter__(self):
        print("上文内容")
        return self

    def __exit__(self, exc_type, exc_value, exc_tb):
        print("下文内容:")
        print(exc_type, exc_value, exc_tb)
        return True

    def show(self):
        print("Student show")
        raise NameError("show NameError")

def main():
    try:
        with Student() as s:
            print("with block: ", s)
            s.show()
    except Exception as e:
        print("try-except: ", e)

if __name__ == "__main__":
    main()
